<?php
/**
 * Класс отвечает за вывод информации
 *
 */
class View_Main {
  public $str = '';
  /**
   * начальный вывод менеждера
   *
   */
  public function showManager($arrTree) {
    $this->str .= '<table id="mainTable" border="1">';
    $this->str .= '<tr>';
    $this->str .= '<th>';
    $this->str .= 'РАЗДЕЛЫ';
    $this->str .= '</th>';
    $this->str .= '<th>';
    $this->str .= '<p class="headFolderName"></p>';
    $this->str .= '</th>';
    $this->str .= '</tr>';
    $this->str .= '<tr>';
      $this->str .= '<td id="tree" rowspan="2">';
        $this->str .= '<div class="convert">';
          $this->str .= $this->getTree($arrTree);
        $this->str .= '</div>';
      $this->str .= '</td>';
          $this->str .= '<td id="files">';
          $this->str .= '<div class="convert">';
            $this->str .= '<div style="display:none" id="ajaxLoader"><img src="' . W_IMAGES .
              'ajax-loader.gif"/></div>';
          $this->str .= '<div id="openFolder"></div>';
        $this->str .= '</div>';
      $this->str .= '</td>';
    $this->str .= '</tr>';
    $this->str .= '<tr>';
      $this->str .= '<td id="menu">';
        $this->str .= '<div id="menuBlock">';
          $this->str .= '<p>';
            $this->str .= '<a href="#TB_inline?height=150&width=300&inlineId=hiddenModalContent" title="Добавить файлы" class="thickbox">добавить файлы</a> ';
            $this->str .= '<a href="javascript:operation.deleteRow(\'file\');">удалить файлы</a> ';
          $this->str .= '</p>';
          $this->str .= '<p>';
            $this->str .= '<a href="#TB_inline?height=100&width=300&inlineId=hiddenModalCreateFolder"  title="Добавить папку" class="thickbox">добавить папки</a> ';
            $this->str .= '<a href="javascript:operation.deleteRow(\'folder\');">удалить папки</a> ';
          $this->str .= '</p>';
        $this->str .= '</div>';
      $this->str .= '</td>';
    $this->str .= '</tr>';
    
    $this->str .= '<tr class="forImage">';
     $this->str .= '<td colspan="2" tyle="padding:0px; margin:0px;">';
      $this->str .= '<img src="123.png" style="display:none;">';
     $this->str .= '</td>';
    $this->str .= '</tr>';
    $this->str .= '</table>';
  }

  /**
   * получаем дерево
   */
  public function getTree($arrTree) {
    foreach ($arrTree as $folder) {
      if (isset($folder['children']))
        $isCildren = true;
      else
        $isCildren = false;

      $this->str .= '<div class="' . ($isCildren ? 'expandable' : 'close') . '" ' . ($folder['ID_root_folder'] ?
        'style="display: none;"' : '') . ' id="folder_' . $folder['ID_folder'] . '">';
      $this->str .= $isCildren ?
        '<a class="open" href="javascript:filemanager.toggleTreeFolderOpen(' . $folder['ID_folder'] .
        ');"></a> ' : '<span class="noOpen"></span>';
      $this->str .= '<a id="folder_a_' . $folder['ID_folder'] .
        '" href="javascript:filemanager.selectFolder(' . $folder['ID_folder'] .
        ');">' . $folder['name'] . '</a>';
      if ($isCildren)
        self::getTree($folder['children']);
      $this->str .= '</div>';
    }
  }

  /**
   * получаем файлы
   *
   */
  public static function getFolder($arrFolders, $arrFiles) {
    $str = '<table id="openFolder">';
    if ($arrFolders) {
      $str .= '<tr class="head"><td colspan="5">Папки</td></tr>';
      $str .= '<tr id="FolderMainRow">';
      $str .= '<td><input type="checkbox" id="selectAllfolder"/></th>';
      $str .= '<td colspan="3">Имя</th>';
      $str .= '<td colspan="3">Создан</th>';
      $str .= '</tr>';
      foreach ($arrFolders as $folder) {
        $str .= '<tr class="folderRow" id="' . $folder['ID_folder'] . '">';
        $str .= '<td class="check"><input type="checkbox"/></td>';
        $str .= '<td colspan="3"><a class="name" href="javascript:filemanager.selectFolder(' .
          $folder['ID_folder'] . ');">' . $folder['name'] . '</a></td>';
        $str .= '<td colspan="3">' . $folder['creation'] . '</td>';
        $str .= '</tr>';
      }
    }
    if ($arrFiles) {
      $str .= '<tr class="head"><td colspan="5">Файлы</td></tr>';
      $str .= '<tr id="fileMainRow">';
      $str .= '<td><input type="checkbox" id="selectAllfile"/></th>';
      $str .= '<td>Имя</td>';
      $str .= '<td>Тип</td>';
      $str .= '<td>Размер</td>';
      $str .= '<td>Создан</td>';
      $str .= '<td></td>';
      $str .= '<td></td>';
      $str .= '</tr>';
      foreach ($arrFiles as $file) {
        $str .= '<tr class="fileRow" id="' . $file['ID_file'] . '">';
        $str .= '<td class="check"><input type="checkbox"/></td>';
        $str .= '<td><span class="name">' . $file['name'] .
          '</span><span class="unique_name" style="display: none;">' . $file['unique_name'] .
          '</span></td>';
        $str .= '<td>';

        $str .= $file['type'];
        $str .= '</td>';
        $str .= '<td>' . round($file['size'] / 1024, 1) . 'kb</td>';
        $str .= '<td>' . Service_Date::getCaseDateForUser($file['creation']) . '</td>';
        $str .= '<td class="check">';
          $str .= '<a target="_blank" href="' . W_ABSPATH . 'getFile?idFile=' . $file['ID_file'] . '">';
            $str .= '<img src="' . W_IMAGES . 'upload.jpg" title="скачать"/>';
          $str .= '</a> ';
        $str .= '</td>';
        
        $str .= '<td class="check">';
          if ($file['type'] == 'audio/wav')
            $str .= '<a href="' . W_ABSPATH . 'content/upload_files/' . $file['unique_name'] . '.png" target="_blink" onMouseOver="operation.getWavImage(\'' . $file['unique_name'] . '\');"><img src="' . W_IMAGES . 'eye.png"></a>';
        $str .= '</td>';        
          
        $str .= '</tr>';
      }
    }
    $str .= '</table>';
    return $str;
  }
} ?>